//
//  QShowPayView.m
//  QoilPublic
//
//  Created by 杨凯 on 16/11/21.
//  Copyright © 2016年 杨凯. All rights reserved.
//

#import "QShowPayView.h"
#import "QPayMoreOrderView.h"



@implementation QShowPayView{

    UIControl *_maskV;
    QPayMoreOrderView *_subV;

    CGFloat W;

}

- (instancetype)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];
    if(self){
        W = 260;
        self.userInteractionEnabled = YES;
        self.frame = frame;
        [self createUI];
        

    }
    return self;
}

- (void)createUI{

    _maskV = [[UIControl alloc] initWithFrame:[UIScreen mainScreen].bounds];
    _maskV.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.5];
    
    _maskV.hidden = YES;
    [self addSubview:_maskV];

    _subV = [[[NSBundle mainBundle] loadNibNamed:@"QPayMoreOrderView" owner:self options:nil] lastObject];
    _subV.frame = CGRectMake((kScreenWidth-W)/2, kScreenHeight, W, W+80);
    
    __block QShowPayView *wself = self;
    _subV.blockA = ^(NSInteger index){
        [wself hidePlayBoxView];
        if(wself.block){
            wself.block(index);
        }
    };
    
    _subV.blockB = ^(NSInteger index){
        [wself hidePlayBoxView];
        if(wself.block){
            wself.block(index);
        }
    };
    [_maskV addSubview:_subV];

}

- (void)setAllMoney:(NSString *)allMoney{

    _allMoney = allMoney;
    _subV.allMoney = _allMoney;

}

- (void)setData:(NSArray *)data{

    _data = data;
    _subV.data = _data;

}

- (void)showPlayBoxView{
    
    UIWindow *window = [[UIApplication sharedApplication].delegate window];
    [window addSubview:_maskV];
    _maskV.hidden = NO;
    _maskV.tag = 2016;
    _maskV.alpha = 0;
    [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.6 initialSpringVelocity:1 options:UIViewAnimationOptionCurveLinear animations:^{
        _subV.center = self.center;
        _maskV.alpha = 1;
    } completion:^(BOOL finished) {
        
    }];
}

- (void)maskAc{
    
    [self hidePlayBoxView];
}


- (void)hidePlayBoxView{
    _maskV.alpha = 1;
    [UIView animateWithDuration:.3 animations:^{
        _subV.frame = CGRectMake((kScreenWidth-(W+50))/2, kScreenHeight, W, W+50);
        _maskV.alpha = 0;
    } completion:^(BOOL finished) {
        _maskV.hidden = YES;
        [_maskV removeFromSuperview];
        [_subV removeFromSuperview];
        [self removeFromSuperview];
    }];
}


@end
